package com.boot.unity.api.modules.training.service.impl;

import com.boot.unity.api.common.Result;
import com.boot.unity.api.modules.training.dao.ChargeStandardDao;
import com.boot.unity.api.modules.training.entity.ChargeStandard;
import com.boot.unity.api.modules.training.service.ChargeStandardService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
 * @author anonymous
 *
 * @create 2020-06-07 10:08:31
 */
@Service
@AllArgsConstructor
public class ChargeStandardServiceImpl implements ChargeStandardService {
    private final ChargeStandardDao chargeStandardDao;

    @Override
    public Result save(ChargeStandard chargeStandard) {
        String inscode = chargeStandard.getInscode();
        Integer seq = chargeStandard.getSeq();
        ChargeStandard standard = chargeStandardDao.getByIncodeAndSeq(inscode,seq);
        int num;
        if (standard == null){
            num = chargeStandardDao.save(chargeStandard);
        }else {
            num = chargeStandardDao.updateByInscodeAndSeq(chargeStandard);
        }
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result deleteByInscodeAndSeq(String inscode, Integer seq) {
        int num = chargeStandardDao.deleteByInscodeAndSeq(inscode,seq);
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }
}
